Skip to content

Conversation

@tanthammar
Copy link
Contributor

@tanthammar tanthammar commented Oct 19, 2025

Fixes #33

Fix Turnstile widget for Livewire dynamic content and collapsing panels

Problem

The current implementation causes issues when used in Livewire components with dynamic content (collapsing panels, SPAs):

  1. Widget disappears after completion
  2. Multiple render attempts - IntersectionObserver + onload callback can both fire, causing Cloudflare to flag as suspicious behavior
  3. No cleanup on component destruction - Causes memory leaks and duplicate widgets when Livewire re-renders
  4. Not following Cloudflare's SPA recommendations - Official docs recommend explicit rendering with cleanup for dynamic content

Fix:

Change Cloudflare Docs Necessary for Livewire?
render=explicit ✅ Recommended for SPAs ✅ YES
onload callback ✅ Official pattern ✅ YES
turnstile.remove() ✅ Required for SPAs ✅ CRITICAL
Using widgetId ✅ All examples use it ✅ YES
Multiple render guard ❌ Not shown ⚠️ Defensive
API already loaded check ✅ Shown in examples ✅ For re-renders

@ousid ousid added the bug Something isn't working label Oct 25, 2025
@ousid ousid merged commit 8a54a32 into coderflexx:2.x Oct 25, 2025
9 checks passed
@ousid
Copy link
Member

ousid commented Oct 25, 2025

@tanthammar Thank you 🙏🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: New instance of Cloudflare Turnstile added to form on scroll

2 participants